package com.atguigu.redis.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @auther zzyy
 * @create 2021-05-02 18:16
 */
@Service
@Slf4j
public class BitMapService
{
    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 模拟有用户来点击首页，每个用户就是不同的ip，不重复记录，重复不记录
     */
    @PostConstruct
    public void init()
    {
        log.info("------模拟后台有用户点击，每个用户ip不同");
        //自己启动线程模拟，实际上产不是线程
        new Thread(() -> {
            for (int i = 1; i <=31; i++) {
                if (i % 2 == 0){
                    redisTemplate.opsForValue().setBit("sign:uid00001:202112", i, Boolean.TRUE);
                }
                if (i % 3 == 0){
                    redisTemplate.opsForValue().setBit("sign:uid00001:202112", i, Boolean.TRUE);
                }
//                redisTemplate.opsForValue().setBit("sign:uid00001:202112", i, Boolean.TRUE);
            }
        },"t1").start();
    }

}
